package org.example.chain.service.impl;

import org.example.chain.service.Validation;

import java.util.ArrayList;
import java.util.List;

public abstract class ValidationChain {
    private List<Validation> chain = new ArrayList<>();

    /**
     * 注册
     * @param validation
     */
    protected void register(Validation validation) {
        chain.add(validation);
    }


    /**
     * 执行责任链
     *
     * @param param
     */
    public void execute(String param) {
        for (int i = 0; i < chain.size(); i++) {
            Validation validation = chain.get(i);
            validation.valid(param);
        }
    }

}
